package uet.sort;

import uet.sort.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class NumberOfSortingActivity extends Activity implements
		OnClickListener {
	private static final int SELECTIONSORT = R.id.algorithm1;
	private static final int QUICKSORT = R.id.algorithm2;
	private static final int SHELLSORT = R.id.algorithm3;

	private EditText eTNumberData;
	private Button ok;
	private TextView nameAlgoSort;
	private int algorithm;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_number_of_data_sort);
		eTNumberData = (EditText) findViewById(R.id.numberOfData);
		ok = (Button) findViewById(R.id.ok);
		nameAlgoSort = (TextView) findViewById(R.id.tVnameAlgoSort1);
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		// Get algorithm chosen
		Intent intent = getIntent();
		Bundle bundle = intent.getExtras();
		algorithm = bundle.getInt("ALGORITHM");
		// Show mesg algorithm chosen to screen
		switch (algorithm) {
		case SELECTIONSORT:
			nameAlgoSort.setText("The Selection Sort is chosen");
			break;
		case QUICKSORT:
			nameAlgoSort.setText("The Quick Sort is chosen");
			break;
		case SHELLSORT:
			nameAlgoSort.setText("The Shell Sort is chosen");
			break;
		default:
			break;
		}
		ok.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.ok:
			// Put Algorithm and number of data sorting
			Intent intentChoose = new Intent("uet.sort.DATASORTING");
			Bundle bundleChoose = new Bundle();
			int numberOfData;
			if (eTNumberData.getText().toString().compareTo("") != 0)
				numberOfData = Integer.parseInt(eTNumberData.getText().toString());
			else
				numberOfData = 0;
			if (numberOfData <= 0 || numberOfData > 10) {
				eTNumberData.setText("");
			} else {
				bundleChoose.putInt("NUMBERDATA", numberOfData);
				bundleChoose.putInt("ALGORITHM", algorithm);
				intentChoose.putExtras(bundleChoose);
				startActivity(intentChoose);
				break;
			}
			break;
		default:
			break;
		}
	}

}
